import webapp2
import jinja2
import os
from google.appengine.api import users
import gdata.spreadsheet.service
import game
import country
import city
import archive
import gameadmin



jinja_environment = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))

        
class MainPage(webapp2.RequestHandler):
    def get(self):
        if users.get_current_user():
            url = users.create_logout_url(self.request.uri)
            url_linktext = 'Logout'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'

        template_values = {
            'url': url,
            'url_linktext': url_linktext,
        }

        template = jinja_environment.get_template('index.html')
        self.response.out.write(template.render(template_values))
        
  
       

app = webapp2.WSGIApplication([('/', MainPage)
							   , ('/([^/]*)/game', game.Index)
                               , ('/game/admin', gameadmin.AdminPage)
                               , ('/game/init-dic', gameadmin.InitDic)
                               , ('/game/init-era', game.InitEra)
                               , ('/game/init-country', game.InitCountry)
                               , ('/game/init-geo', game.InitGeo)
                               , ('/game/init-dictionaryEn', game.InitDictionaryEn)
                               , ('/game/init-dictionaryCn', game.InitDictionaryCn)
                               , ('/game/language', game.LanguagePage) 
                               , ('/game/language/change', game.LanguageChange)
                               , ('/([^/]*)/game/archive/new', archive.AddPage) 
                               , ('/([^/]*)/game/archive/load', archive.Index)  
                               , ('/([^/]*)/game/archive/create-page/era/([^/]*)', archive.ChooseCountryPage) 
                               , ('/([^/]*)/game/archive/create-page/era/([^/]*)/country/([^/]*)/add-archive', archive.Add)  
                               , ('/([^/]*)/game/create-country', country.Add)                                                                                                                                                    
							   , ('/([^/]*)/game/create-country-page', country.AddPage)       
                               , ('/([^/]*)/game/country/(.*)/create-city-page', city.AddPage)     
                               , ('/([^/]*)/game/country/(.*)/create-city', city.Add)                                                                                                                                                
                               , ('/([^/]*)/game/archive/([^/]*)/era/([^/]*)/country/([^/]*)', country.Index)                                                                                                                                                 
                               , ('/([^/]*)/game/archive/([^/]*)/era/([^/]*)/country/([^/]*)/citys' , country.CityList)   
                               , ('/([^/]*)/game/archive/([^/]*)/era/([^/]*)/country/([^/]*)/city/([^/]*)' , city.Index) 
                               , ('/([^/]*)/game/archive/([^/]*)/era/([^/]*)/country/([^/]*)/city/([^/]*)/taxPage' , city.TaxPage)           
                               , ('/([^/]*)/game/archive/([^/]*)/era/([^/]*)/country/([^/]*)/info' , country.Info)                                                                                                                                                                                           
                                                                                                                                      					                       
                              ],
                              debug=True)
